#ifndef _MOTOR_CONFIG_H_
#define _MOTOR_CONFIG_H_

#include "include.h"
#include "user_include.h"

#define SET_PWM_ch0_1(x)     (STMR0_CMPAH = (u8)(x>>8), STMR0_CMPAL = x&0xff, STMR_LOADEN = 0x00, STMR_LOADEN |= 0x03)
#define SET_PWM_ch2_3(x)     (STMR2_CMPAH = (u8)(x>>8), STMR2_CMPAL = x&0xff, STMR_LOADEN = 0x00, STMR_LOADEN |= 0x0c)
#define SET_PWM_ch4_5(x)     (STMR4_CMPAH = (u8)(x>>8), STMR4_CMPAL = x&0xff, STMR_LOADEN = 0x00, STMR_LOADEN |= 0x30)

// #define SET_A_PWM(x)     SET_PWM_ch0_1(x)
// #define SET_B_PWM(x)     SET_PWM_ch2_3(x)

//adc----------------------------------
#define ADC_THETA_PIN   0x08    //P10
#define ADC_VSP_PIN     0x0A    //P12
#define ADC_NTC_PIN     0x05    //P05
// #define ADC_CUR_PIN     0x05    //amp1
#define ADC_CUR_PIN     0x16    //P26

#define IS_ADC0_FIN()   (ADC_STA & 0x02)
#define IS_ADC1_FIN()   (ADC_STA & 0x04)
#define IS_ADC2_FIN()   (ADC_STA & 0x08)

#define CLR_ADC0_FIN()   (ADC_STA |= 0x02)
#define CLR_ADC1_FIN()   (ADC_STA |= 0x04)
#define CLR_ADC2_FIN()   (ADC_STA |= 0x08)

#define ADC_CH0_SET_EXT(ch)     ADC_CHS0 = 0x80 | (ch & 0x1f)//Ĭ���Ҷ��룬
#define ADC_CH1_SET_EXT(ch)     ADC_CHS1 = 0x80 | (ch & 0x1f)//Ĭ���Ҷ��룬
#define ADC_CH2_SET_EXT(ch)     ADC_CHS2 = 0x80 | (ch & 0x1f)//Ĭ���Ҷ��룬

#define ADC_CH0_SET_INT(ch)     ADC_CHS0 = 0xa0 | (ch & 0x1f)//Ĭ���Ҷ��룬
#define ADC_CH1_SET_INT(ch)     ADC_CHS1 = 0xa0 | (ch & 0x1f)//Ĭ���Ҷ��룬
#define ADC_CH2_SET_INT(ch)     ADC_CHS2 = 0xa0 | (ch & 0x1f)//Ĭ���Ҷ��룬

#define ADC_CH0_START()     ADC_CFG0 |= 0x01
#define ADC_CH1_START()     ADC_CFG0 |= 0x02
#define ADC_CH2_START()     ADC_CFG0 |= 0x04

#define ADC0_GET_DATA(h,l)  h=ADC_DATAH0;l=ADC_DATAL0;
#define ADC1_GET_DATA(h,l)  h=ADC_DATAH1;l=ADC_DATAL1;
#define ADC2_GET_DATA(h,l)  h=ADC_DATAH2;l=ADC_DATAL2;

#define ADC0_GET_DATA_S()   (ADC_DATAH0<<8) | ADC_DATAL0;
#define ADC1_GET_DATA_S()   (ADC_DATAH1<<8) | ADC_DATAL1;
#define ADC2_GET_DATA_S()   (ADC_DATAH2<<8) | ADC_DATAL2;

//adc======================================

//motor-------------------------------------
#define ADC_GET_CURRENT_START()     ADC_CH0_SET_EXT(ADC_CUR_PIN);ADC_CH0_START();
// #define ADC_GET_CURRENT_START()     ADC_CH0_SET_INT(ADC_CUR_PIN);ADC_CH0_START();
#define ADC_GET_ANGLE_START()       ADC_CH1_SET_EXT(ADC_THETA_PIN);ADC_CH1_START();
#define ADC_GET_VDC_START()
#define ADC_GET_NTC_START()

//motor=====================================
#endif

